<?php
// No direct access to this file
	defined('_JEXEC') or die('Restricted access');		
	
?>
<?php
	$url = $this->baseurl.'/images/com_retailshop/';	
	$caregory = '';
?>

<?php 
    if(isset($this->getallshopbyUser))
    {
    	$url = $this->baseurl.'/images/com_retailshop/';	    	
    	for($i = 0 ; $i < count($this->catagorys_Menu); $i++){
    		if($i!=3)
    			$caregory .= '<li><a href="index.php?option=com_retailshop&view=home&task=detailscatelog&id='.$this->catagorys_Menu[$i]->id.'">'.$this->catagorys_Menu[$i]->name.'</a></li>';
    		else{
    			$caregory .= '<li class="last"><a href="index.php?option=com_retailshop&view=home&task=detailscatelog&id='.$this->catagorys_Menu[$i]->id.'">'.$this->catagorys_Menu[$i]->name.'</a></li>';
    			break;
    		}
    	}
    }
    
?>
<div id="main">
    	<div class="wrapper wmain">
        	<div id="main-premium">
                <?php if(!isset($this->getallshopbyUser)): ?>
                <div class="slideshow">
                    <div class="slider-wrapper theme-default">
                        <div id="slider" class="nivoSlider">
							<?php if(isset($this->slideshow) && count($this->slideshow) > 0 ){ ?>
							<?php foreach($this->slideshow as $slide){ ?>
							
							<?php 
								$temp = explode('/',$slide->image_url);		
								$img = $temp[count($temp)-1];
							?>
							
							<a href="<?php echo $slide->link; ?>"><img src="<?php echo $url.''.$img; ?>" width="700" height="350" title="<?php echo $slide->title; ?>"/></a>
						   
						   <?php } }else { ?>
                           <a href="#"><img src="<?php echo $url.'sdidedefault.jpg'; ?>" width="700" height="350" title="This shop has not selected a picture of the slideshow"/></a>
						   <?php } ?>                           
                        </div>
                    </div>
                </div>
                <?php endif; ?>
                <div class="main-content">
				<?php if(!isset($this->getallshopbyUser)) { ?>
                	<div id="best-deals" class="list">
                    	<div class="head-box">
                        	<h4>Best Deals
							<?php if(count($this->deals) > 6) { ?>
								<div class="page-list">
									<span>Page</span>
									  <select name="page" id="pagedeals">
										<?php for($i =1; $i< count($this->deals)/6+1; $i++){ ?>
										<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
										<?php } ?>
									</select>
								</div>
							<?php } ?>
                            </h4>
                        </div>
                         <?php if(count($this->deals) == 0){ ?><div  class="no-item"><p class="no-product">NO PRODUCT</p></div>
							<?php }else{ ?>
                        <ul class="product" id="productdeals">
							<?php for($i=0;$i<count($this->deals) && $i < 6; $i++){ 
								$img_url = ($this->deals[$i]->image_url =='')?$url.'noimages.jpg':$url.''.$this->deals[$i]->image_url;							
							?>
								<li <?php if(($i+1)%3 == 0) echo 'class="last"'; if($i>=3) echo 'style="margin-top: 10px;"'; ?>>
									<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $this->shop->id; ?>&id=<?php echo $this->deals[$i]->id; ?>"><center><img src="<?php echo $img_url; ?>" width="200" height="170" /></center></a>
									
									<h2 class="product-name">
										<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $this->shop->id; ?>&id=<?php echo $this->deals[$i]->id; ?>"><?php echo $this->deals[$i]->name; ?></a>
									</h2>
									<div class="price-box">
										<p class="price-new">
											<span class="price-label">Price:</span>
											<?php $price = $this->deals[$i]->price - $this->deals[$i]->promotion*$this->deals[$i]->price/100; ?>
											<span id="product-price" class="price"><s><?php echo number_format($this->deals[$i]->price,2); ?> $</s> - <?php echo number_format($price,2); ?> $</span>
										</p>
									</div>
									
									<div id="clock_<?php echo $this->deals[$i]->id; ?>" class="clock" style="<?php echo $this->deals[$i]->timetime; ?>" >
										  <p>
											<span id="hours_<?php echo $this->deals[$i]->id; ?>"></span>
											Hours
										  </p>
										  <div class="space">:</div>
										  <p>
											<span id="minutes_<?php echo $this->deals[$i]->id; ?>"></span>
											Minutes
										  </p>
										  <div class="space">:</div>
										  <p>
											<span id="seconds_<?php echo $this->deals[$i]->id; ?>"></span>
											Seconds
										  </p>
									</div>									
									<div class="free-gift">
										<span><?php if(strlen($this->deals[$i]->free_gift) > 0 )echo 'FREE GIFT: '.$this->deals[$i]->free_gift; ?></span>
									</div>
									
								</li>
							<?php } } ?>
                        </ul>
						
                </div>
                <div id="products" class="list">
					<form>
						<div class="head-box">
							<h4>Products
								<?php if(count($this->products) > 6) { ?>
								<div class="page-list">
									<span>Page</span>									
									 <select name="page" id="page">						  
										<?php for($i =1; $i< count($this->products)/6+1; $i++){ ?>
										<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
										<?php } ?>
									  </select>									
								</div>
								<?php } ?>
							</h4>
							
						</div>
                        <?php $i = 0; ?>
						
							 <?php if($this->products == null){ ?><div  class="no-item"><p class="no-product">NO PRODUCT</p></div>
								<?php }else{ ?>
						<ul class="product" id ="product">						
								<?php for($i=0;$i<count($this->products)&& $i < 6; $i++){ 
									$img_url = ($this->products[$i]->image_url =='')?$url.'noimages.jpg':$url.''.$this->products[$i]->image_url;
								?>
									<li <?php if(($i+1)%3 == 0) echo 'class="last"'; if($i>=3) echo 'style="margin-top: 10px;"'; ?>>
										<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $this->shop->id; ?>&id=<?php echo $this->products[$i]->id; ?>"><center><img src="<?php echo $img_url; ?>" width="200" height="170" /></center></a>

										<h2 class="product-name">
											<a href="index.php?option=com_retailshop&view=myshop&task=productdetail&shop_id=<?php echo $this->shop->id; ?>&id=<?php echo $this->products[$i]->id; ?>"><?php echo $this->products[$i]->name; ?></a>
										</h2>
										<div class="price-box">
											<p class="price-new">
												<span class="price-label">Price:</span>
												<?php $price = $this->products[$i]->price - $this->products[$i]->promotion*$this->products[$i]->price/100; ?>
												<span id="product-price" class="price">$<?php echo number_format($price,2); ?></span>
											</p>
										</div>
										
										<div class="free-gift">
											<span><?php echo $this->products[$i]->free_gift; ?></span>
										</div>
										
									</li>
								<?php } } ?>
						</ul>
						
					</form>
                </div>
				<?php }else { ?>
				<div id="list-shop">
					<h4>List My Shop </h4>
					<div class="list-my-shop">
						<?php foreach($this->getallshopbyUser as $shop){
							$logo = $shop->logo;
							if(strlen($logo)>4){
								$logo = $url.'logo/'.$logo;
							}else{
								$logo = $url.'noimages.jpg';
							}
						?>
							<div class="shop">
									<a href="index.php?option=com_retailshop&view=myshop&shop_id=<?php echo $shop->id; ?>&true"><span class="shop-photo"><img width="70" height="70" src="<?php echo $logo; ?>"></span></a>
									<div class="shop-info my-shop">
										<div class="shop-head">
											<a href ="index.php?option=com_retailshop&view=myshop&shop_id=<?php echo $shop->id; ?>&true"><span><?php echo $shop->name; ?></span></a>
										</div>
										<div class="shop-add">
											<span><?php echo $shop->address; ?></span>
										</div>
										<div class="shop-short-des">
											<span><?php echo substrCustom($shop->short_description,0,200); ?></span>
										</div>
									</div>
							</div>
						<?php } ?>									
					</div>
				</div>
				
				<?php } ?>
            </div>
           </div> 
          <div id="main-search">
            <?php if(isset($this->getallshopbyUser)): ?>
          	<div id="search-body" class="block"> 
                <h4>Search</h4>
                <form name="form" id="form">
                  <ul>
                      <li class="first">
                         <select class="select" id="country_select">
							<option value="-1"> --- Please Select --- </option>
						<?php foreach($this->countrys as $c) { ?>
							<option value="<?php echo $c->id?>"><?php echo $c-> name; ?></option>          
						<?php } ?>
						</select>
                      </li>
                      <li>
                        <select class="select" id="city_select">
                        <option value="-1"> --- Please Select --- </option>                    
                    </select>
                      </li>
                      <li>
                        <select class="select" id="category_">
							<option value="-1"> --- Select Category --- </option>
							<?php foreach($this->catagorys as $c) { ?>
							<option value="<?php echo $c->id?>"><?php echo $c-> name; ?></option>          
							<?php } ?>                      
						</select>
                      </li>
                      <li>
							<input type="text" id="brand_" class="" name="brand" placeholder="Brand"/>
                      </li>
                  </ul>
                  <button type="submit" id="btnsearchshop">Find</button>
                 </form>
			</div>

<div id="category-block" class="block">
              	<h4>Category</h4>
                <div class="block-content">
                	<ul>
						<?php if($this->catagorys ==null){ ?>
						<li class="no-category">NO CATEGORY</li>
						<?php }else{ ?>
						<?php foreach($this->catagorys as $c){ ?>
						<li><a a href="index.php?option=com_retailshop&view=home&task=detailscatelog&id=<?echo $c->id;?>"><?php echo $c->name; ?></a></li>
						<?php }} ?>
                    </ul>
                </div>
             </div>
             	
            <div id="list-events" class="block">
            	<h4>List Events</h4>
                <ul class="carou">
					<?php if ($this->eventsAll == null){ ?>
					<li class="no-event">NO EVENT</li>
					<?php }else { ?>
					<?php foreach($this->eventsAll as $e){ ?>
                	<li>
						<a href="index.php?option=com_retailshop&view=myshop&task=eventdetail&idp=<?php echo $e->id; ?>&shop_id=<?php echo $e->shop_id; ?>"><p><?php echo $e->title; ?></p></a>
						<span class="from">From: </span>
						<span class="start-date"><?php echo substr($e->start_date,0,10)?></span>
						- <span class="to">To: </span>
						<span class="end-date"><?php echo substr($e->end_date,0,10); ?></span>
					</li>                    
					<?php } } ?>
                </ul>
            </div> 
             
<div id="aboutus" class="block">
              		<h4>About us</h4>
                    <div class="text">
                        <h2>Retailshop.info</h2>
                        <p>Best place to find out on going activities happening right there at local retail shop.</p>
            			<p>For Example : Despite of, a coffee shop which I can see from my office ,going to that place I will track it from my office  and will order him or grab  the coupon also.</p>
                        <a href="#">Read more</a>
                    </div>
            </div>
            <?php else: ?>
            <div id="detail-shop" class="block">				
				<?php echo $this->loadTemplate('header');?>
            </div>
			<div id="category-block" class="block">
              	<h4>Category</h4>
                <div class="block-content">
                	<ul>
						<?php if($this->categorys == null){ ?>
						<li class="no-category">NO CATEGORY</li>
						<?php }else{ ?>
						<?php foreach($this->categorys as $c){ 
							$shop_is='';
							if(isset($this->shop_id))
								$shop_is='&shop_id='.$this->shop_id;
						?>
						<li><a a href="index.php?option=com_retailshop&view=myshop&task=products&idp=<?php echo $c->id.$shop_is; ?>"><?php echo $c->name; ?></a></li>
						<?php }} ?>
                    </ul>
                </div>
              </div>
            
            <div id="list-events" class="block">
            	<h4>List Events</h4>
                <ul class="carou">
					<?php if ($this->events == null){ ?>
					<li class="no-event">NO EVENT</li>
					<?php }else { ?>
					<?php foreach($this->events as $e){ ?>
                	<li>
						<a href="index.php?option=com_retailshop&view=myshop&task=eventdetail&idp=<?php echo $e->id; ?>&shop_id=<?php echo $e->shop_id; ?>"><p><?php echo $e->title; ?></p></a>
						<span class="from">From: </span>
						<span class="start-date"><?php echo substr($e->start_date,0,10)?></span>
						- <span class="to">To: </span>
						<span class="end-date"><?php echo substr($e->end_date,0,10); ?></span>
					
					</li>                    
					<?php } } ?>
                </ul>
            </div> 
            <?php endif; ?>
          </div>          
       </div>
    </div>
<script type="text/javascript">
	$(document).ready(function(){	
		$(window).load(function() {
			$('#slider').nivoSlider();		
			//$('#cat').html('<?php echo $caregory; ?>');		
		});		
		$("#page").change(function(){			
			var page =  $(this).val();	
			var shop_id =  '<?php echo $this->shop_id; ?>';										
			var deals = 'false';
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limitproduct",
				data:{page:page,shop_id:shop_id,deals:deals},
				type: "POST",
				dataType: "html",
				success:function(data) {									
					$('#product').html(data);
				},
				error: function (){
					alert('loi');
				}
			});						
		});		
		$("#pagedeals").change(function(){			
			var page =  $(this).val();	
			var shop_id =  '<?php echo $this->shop_id; ?>';										
			var deals = 'true';
			$.ajax({	
				url:"index.php?option=com_retailshop&view=myshop&task=limitproduct",
				data:{page:page,shop_id:shop_id,deals:deals},
				type: "POST",
				dataType: "html",
				success:function(data) {					
					$('#productdeals').html(data);
				},
				error: function (){
					alert('loi');
				}
			});						
		});	
	});    
</script>
<script type="text/javascript" charset="utf-8">
    $(function() {
     
      $(document).ready(function(){
			$(".clock").each(function(){
				var id = $(this).attr("id");
				var dateAviable = $(this).attr("style");
				dateAviable = Number(dateAviable).valueOf();
				LoadClock(id,dateAviable);
			});
		});
      
		function LoadClock(id,dateAviable)
		{
			var arr = id.split("_");
			var deadl_id = arr[1];
			 var currentDate = new Date();
			  finished = false;	
			$("div#" + id).countdown(dateAviable + currentDate.valueOf(),function(event){
				 $this = $(this);
				switch(event.type) {
  				case "seconds":
  				case "minutes":
  				case "hours":
  				case "days":
  				case "weeks":
  				case "daysLeft":
  				  $this.find('span#'+event.type + "_" + deadl_id).html(event.value);
  				  if(finished) {
  				    $this.fadeTo(0, 1);
  				    finished = false;
  				  }
  					break;
  				case "finished":
				$this.fadeTo('slow', .5);
				finished = true;
  					break;
				}
			});
		}
  		
  		$('select#exampleDate').change(function() {
  		  try {
    		  var $this = $(this),
    		      value;
  		    currentDate = new Date();
    		  switch($this.attr('value')) {
    		    case "other":
    		      value = prompt('Set the date to countdown:\nThe hh:mm:ss parameters are opitionals', 'YYYY/MM/DD hh:mm:ss');
    		      break;
    		    case "daysFromNow":
    		      value = prompt('How many days from now?', '');
    		      value = new Number(value) * 24 * 60 * 60 * 1000 + currentDate.valueOf();
    		      break;
    		    case "minutesFromNow":
    		      value = prompt('How many minutes from now?', '');
    		      value = new Number(value) * 60 * 1000 + currentDate.valueOf();
    		      break;
    		    default:
    		      value = availiableExamples[$this.attr('value')] + currentDate.valueOf();
    		  }
    		  $('div#clock').countdown(value, callback);
    		  $this.find('option:first').attr('selected', true);
    		} catch(e) { alert(e); }
  		});
  	});
  </script>
<?php	if($_SESSION['__default']['user']->id != 0 && isset($this->main)){ ?>
<script>	
	$(document).ready(function(){	
		var curthml = '<?php echo $caregory; ?>';
		var settting = '<li><a href="index.php?option=com_retailshop&view=myshop&task=setting&shop_id=<?php echo $this->shop_id; ?>">Setting</a></li>';
		
		$('#cat').html(curthml+settting);		
	});
</script>
<?php	}else {
	unset($_SESSION['shopid']);    ?>
    <script>	
	$(document).ready(function(){	
		var curthml = '<?php echo $caregory; ?>';		
		
		$('#cat').html(curthml);		
	});
</script>
<?php } ?>